home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1993-1997 Fabrizio Oddone
- ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
- This source code is distributed as freeware:
- you may copy, exchange, modify this code.
- You may include this code in any kind of application: freeware,
- shareware, or commercial, provided that full credits are given.
- You may not sell or distribute this code for profit.
- */
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef __FSPCOMPAT__
- #include <FSpCompat.h>
- #endif
-
- #include "CursorBalloon.h"
- #include "FabWList.h"
- #include "FabWmemman.h"
- #include "FabTaskManager.h"
-
- #include "Globals.h"
- #include "Assembler.h"
- #include "DragManSim.h"
- #include "myMemory.h"
-
-
- struct deferFileAction {
- OSType theType;
- FSSpec theFS;
- };
-
-
- typedef struct myglobptr {
- Boolean canAcceptDrag;
- Boolean inContent;
- } GlobalsData, *GlobalsPtr;
-
- GlobalsData gmyGlobals;
-
- static pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag);
- static Boolean IsMyTypeAvailable(WindowPtr theWindow, DragReference theDrag);
- static pascal OSErr MyReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
- DragReference theDrag);
-
- static void deferredFileAction(void *param);
-
- /*
- OSErr MyInitDragManager(void)
- {
- OSErr err;
-
- err = InstallTrackingHandler(MyDefaultTrackingHandler, 0L, &myGlobals);
- if (err == noErr)
- err = InstallReceiveHandler(MyDefaultReceiveHandler, 0L, &myGlobals);
-
- return err;
- }
- */
-
- OSErr MyInstallHWindow(WindowPtr theWindow)
- {
- FabWindowPtr thefabw;
- OSErr err;
-
- if (thefabw = GetFabWindowPtr(theWindow)) {
- thefabw->trackUPP = NewDragTrackingHandlerProc(MyTrackingHandler);
- thefabw->recUPP = NewDragReceiveHandlerProc(MyReceiveHandler);
-
- if ((err = InstallTrackingHandler(thefabw->trackUPP, theWindow, &gmyGlobals)) == noErr) {
- err = InstallReceiveHandler(thefabw->recUPP, theWindow, &gmyGlobals);
- if (err)
- RemoveTrackingHandler(thefabw->trackUPP, theWindow);
- }
- // else
- // DebugStr("\pMyInstallHWindow error on InstallTrackingHandler");
- }
- return err;
- }
-
- void MyRemoveHWindow(WindowPtr theWindow)
- {
- FabWindowPtr thefabw;
-
- if (thefabw = GetFabWindowPtr(theWindow)) {
- (void) RemoveTrackingHandler(thefabw->trackUPP, theWindow);
- (void) RemoveReceiveHandler(thefabw->recUPP, theWindow);
- if (thefabw->trackUPP) {
- DisposeRoutineDescriptor(thefabw->trackUPP);
- thefabw->trackUPP = nil;
- }
- if (thefabw->recUPP) {
- DisposeRoutineDescriptor(thefabw->recUPP);
- thefabw->recUPP = nil;
- }
- }
- }
-
- pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
- void *handlerRefCon, DragReference theDrag)
- {
- Rect tempRect = {0, 0, 0, 0};
- GlobalsPtr myGlobals = (GlobalsPtr) handlerRefCon;
- Point mouse, localMouse;
- void (*theProc)(WindowPtr, RectPtr);
- DragAttributes attributes;
- RgnHandle hiliteRgn;
- FabWindowPtr thefabw;
- OSErr err;
-
- if ((err = GetDragAttributes(theDrag, &attributes)) == noErr) {
- switch(theMessage) {
- // case dragTrackingEnterHandler:
- // break;
- case dragTrackingEnterWindow:
- myGlobals->canAcceptDrag = IsMyTypeAvailable(theWindow, theDrag);
- myGlobals->inContent = false;
- break;
- case dragTrackingInWindow:
- if (myGlobals->canAcceptDrag) {
- if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr) {
- localMouse = mouse;
- GlobalToLocal(&localMouse);
- if (attributes & dragHasLeftSenderWindow) {
- if (thefabw = GetFabWindowPtr(theWindow)) {
- theProc = thefabw->getDragHiliteRectProc;
- if (theProc)
- theProc(theWindow, &tempRect);
- }
- if (PtInRect(localMouse, &tempRect)) {
- if (myGlobals->inContent == false) {
- hiliteRgn = NewRgn();
- if (hiliteRgn) {
- //InsetRect(&tempRect, 1, 1);
- RectRgn(hiliteRgn, &tempRect);
- (void) ShowDragHilite(theDrag, hiliteRgn, true);
- DisposeRgn(hiliteRgn);
- }
- myGlobals->inContent = true;
- }
- }
- else {
- if (myGlobals->inContent) {
- (void) HideDragHilite(theDrag);
- myGlobals->inContent = false;
- }
- }
- }
- }
- // MyTrackItemUnderMouse(localMouse, theWindow);
- }
- break;
- case dragTrackingLeaveWindow:
- if (myGlobals->canAcceptDrag && myGlobals->inContent) {
- (void) HideDragHilite(theDrag);
- }
- myGlobals->canAcceptDrag = false;
- break;
- // case dragTrackingLeaveHandler:
- // break;
- }
- }
- return err;
- }
-
- Boolean IsMyTypeAvailable(WindowRef theWindow, DragReference theDrag)
- {
- HFSFlavor hfsData;
- PromiseHFSFlavor phfsData;
- //HVolumeParam mypb;
- FSSpec copySpec;
- //HFSFlavor *theData;
- //AliasHandle tempFolder;
- Size dataSize;
- //FlavorFlags theFlags;
- ItemReference theItem;
- unsigned short items, index;
- OSErr err;
- Boolean targetFolder, isAnAlias;
- Boolean retVal = true;
-
-
- if ((err = CountDragItems(theDrag, &items)) == noErr) {
- for (index = 1; (index <= items) && retVal; index++) {
- if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
- dataSize = sizeof(PromiseHFSFlavor);
- if (err = GetFlavorData(theDrag, theItem, flavorTypePromiseHFS, &phfsData, &dataSize, 0L)) {
- dataSize = sizeof(HFSFlavor);
- if (noErr == (err = GetFlavorData(theDrag, theItem, flavorTypeHFS, &hfsData, &dataSize, 0L))) {
- switch (hfsData.fileType) {
- case kFTY_REG:
- retVal = theWindow == gWPtr_Registers;
- break;
- case kFTY_RAM:
- case 'TEXT':
- retVal = theWindow == gWPtr_Disasm || theWindow == gWPtr_Dump;
- break;
- default:
- retVal = false;
- }
- if (retVal) {
- copySpec = hfsData.fileSpec;
- if (err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias))
- retVal = false;
- }
- }
- else
- retVal = false;
- }
- }
- else
- retVal = false;
- }
- }
- else
- retVal = false;
- return retVal;
- }
-
- pascal OSErr MyReceiveHandler(WindowPtr /*theWindow*/, void *handlerRefCon,
- DragReference theDrag)
- {
- GlobalsPtr myGlobals = (GlobalsPtr) handlerRefCon;
- //HVolumeParam mypb;
- HFSFlavor hfsData;
- PromiseHFSFlavor phfsData;
- FInfo myInfo;
- FSSpec copySpec;
- //AliasHandle tempFolder;
- //Point mouse;
- ItemReference theItem;
- //FlavorFlags theFlags;
- Size dataSize;
- struct deferFileAction *param;
- void *theTask;
- unsigned short items, index;
- OSErr err = noErr;
- Boolean targetFolder, isAnAlias;
-
- //if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr)
- if (myGlobals->canAcceptDrag && myGlobals->inContent) {
- if ((err = CountDragItems(theDrag, &items)) == noErr) {
- for (index = 1; (index <= items) && (err == noErr); index++) {
- if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
- // if ((err = GetFlavorFlags(theDrag, theItem, flavorTypeHFS, &theFlags)) == noErr)
- dataSize = sizeof(PromiseHFSFlavor);
- if ((err = GetFlavorData(theDrag, theItem, flavorTypePromiseHFS, &phfsData, &dataSize, 0L)) == noErr) {
- dataSize = sizeof(FSSpec);
- hfsData.fileType = kContainerAliasType;
- err = GetFlavorData(theDrag, theItem, phfsData.promisedFlavor, &hfsData.fileSpec, &dataSize, 0L);
- }
- else {
- dataSize = sizeof(HFSFlavor);
- err = GetFlavorData(theDrag, theItem, flavorTypeHFS, &hfsData, &dataSize, 0L);
- }
- if (err == noErr) {
- copySpec = hfsData.fileSpec;
- if ((err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias)) == noErr) {
- if (targetFolder == false) {
- if ((err = FSpGetFInfoCompat(©Spec, &myInfo)) == noErr) {
- switch (myInfo.fdType) {
- case kFTY_REG:
- case kFTY_RAM:
- case 'TEXT':
- param = fmalloc(sizeof(struct deferFileAction));
- if (param) {
- param->theType = myInfo.fdType;
- param->theFS = copySpec;
- theTask = Fab_CreateSystemTask(deferredFileAction, param, true);
- if (theTask) {
- Fab_ScheduleSystemTask(theTask);
- }
- else {
- err = dragNotAcceptedErr;
- ffree(param);
- }
- }
- else
- err = dragNotAcceptedErr;
- break;
- default:
- err = dragNotAcceptedErr;
- }
- }
- }
- else
- err = dragNotAcceptedErr;
- }
- }
- //
- }
- }
- }
- }
- else
- err = dragNotAcceptedErr;
-
- if (err)
- err = dragNotAcceptedErr;
- return err;
- }
-
- void deferredFileAction(void *param)
- {
- struct deferFileAction *myData = param;
- OSErr err;
-
- switch (myData->theType) {
- case kFTY_REG:
- err = OpenProcessorState(&myData->theFS);
- UnloadSeg(OpenProcessorState);
- break;
- case kFTY_RAM:
- err = myOpenFile(&myData->theFS, gMMemory, kSIZE_RAM);
- UnloadSeg(myOpenFile);
- break;
- case 'TEXT':
- err = myAsmFile(&myData->theFS);
- UnloadSeg(myAsmFile);
- break;
- }
- ffree(myData);
- }
-
-